// PROGRAMA : SCRP120A
// SISTEMA : SISP - SISTEMA DE INFORMACOES DE SEGURANCA PUBLICA
// IDENTIFICACAO CRIMINAL
// BIBLIOTECA : SISP
// CLIENTE : GEJUSPC - GERENCIA DE ESTADO DA JUSTICA, SEGURANCA
// PUBLICA E CIDADANIA / INSTITUTO DE IDENT.
// OBJETIVO : ALTERACAO DA FICHA DE INDICE CRIMINAL
// PROGRAMADOR: JOSE ANTONIO COELHO
// DATA : 29 DE JULHO DE 1997
// ALTERACAO
// ATUALIZACAO: FONETIZACAO DO NOME COMPLETO, NOME DO PAI, NOME
// DA MAE E ALCUNHAS NO ARQUIVO SIC-CADASTRO.
// POR : CARLOS HENRIQUE EM DATA: 18/11/1998
// POR : SOLON MIRANDA EM DATA: 18/02/1999
// POR : SOLON MIRANDA EM DATA: 19/08/1999
package br.com.vti.sisp_sicrim.antigo.controller.programa;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm2000;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm2100;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm220a;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm2300;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrp120aA;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrp120aC;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrp120aG;
import br.com.vti.sisp_sicrim.antigo.model.DidRg;
import br.com.vti.sisp_sicrim.antigo.model.Estla001;
import br.com.vti.sisp_sicrim.antigo.model.SicCadastro;
import br.com.vti.sisp_sicrim.antigo.model.SicNumero;
import br.com.vti.sisp_sicrim.antigo.model.SicSenha;
import br.com.vti.sisp_sicrim.antigo.util.ExceptionProgram;
import br.com.vti.sisp_sicrim.antigo.util.Scrg001;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe : Scrp120a OBJETIVO : ALTERACAO DA FICHA DE INDICE CRIMINAL *
 * 
 * @author Incode - Data: mai/2014
 * 
 */
@Resource
@Path("/antigo/scrp120a")
public class Scrp120a {
	// Views utilizadas
	SicCadastro criminalView = new SicCadastro();
	SicNumero numeroView = new SicNumero();
	SicSenha senhaView = new SicSenha();
	DidRg vwdidrg = new DidRg();
	// Telas/relatorios utilizados
	Scrm2000 scrm2000;
	Scrm2100 scrm2100;
	Scrm220a scrm220a;
	Scrm2300 scrm2300;
	Scrp120aA scrp120aA;
	Scrp120aC scrp120aC;
	Scrp120aG scrp120aG;
	// Includes utilizados
	Estla001 estla001 = new Estla001();
	// Areas globais / session
	Scrg001 scrg001;
	// Funcoes/subrotinas
	FuncoesGerais funcoes = new FuncoesGerais();
	Scrp120a scrp120a;
	Result result;
	Sessao sessao;
	Boolean primeiraVez = false;
	Scrp120a scrp120aAnterior;
	String faseproc = "0";
	String mensagemInicial = "";

	// private String chave = "A";
	private String dmanas = "";
	private int jMax = 168;
	private long jUltNum = 0;
	private String jMaeLimpa = "";
	private String jCrime = "";
	private int jInd1 = 0;
	private int jInd2 = 0;
	private static final String jDozeAster = "************";
	private int horax = 0;
	private int horat = 0;
	private int var = 0;
	// VARIAVEIS DA ESTATISTICA
	private String mod = "";
	private int vlt = 0;
	private String isn = "";
	private String[] tabm = { "", "   ", "VEI", "CON", "MUL", "   ", "IPV", "ROU", "   ", "   ", "   ", "   ", "   ", "IDC", "ICR", "FUN", "   ", "   " };

	private Scrm2000 preMapas() {
		sessao.getScrg001().setWContadorw(0);
		sessao.getScrg001().setWProgramaw(this.getClass().getSimpleName().toUpperCase());
		sessao.getScrg001().setWFuncaow("*** ALTERACAO ***");

		scrm2000 = new Scrm2000(true, sessao);
		scrm2100 = new Scrm2100(true, sessao);
		scrm220a = new Scrm220a(true, sessao);
		scrm2300 = new Scrm2300(true, sessao);
		scrp120aA = new Scrp120aA(true, sessao);
		scrp120aC = new Scrp120aC(true, sessao);
		scrp120aG = new Scrp120aG(true, sessao);

		scrm2000.setDataCorrente(UtilBean.obtemDataDia());
		scrm2100.setDataCorrente(UtilBean.obtemDataDia());
		scrm220a.setDataCorrente(UtilBean.obtemDataDia());
		scrm2300.setDataCorrente(UtilBean.obtemDataDia());

		return scrm2000;
	}

	public Scrp120a(Result result, Sessao sessao) {
		this.result = result;
		this.sessao = sessao;
	}

	@Post
	public void executar(Scrm2000 scrm2000, Scrm2100 scrm2100, Scrm220a scrm220a, Scrm2300 scrm2300, Scrp120aA scrp120aA, Scrp120aC scrp120aC, Scrp120aG scrp120aG) {
		try {
			main(scrm2000, scrm2100, scrm220a, scrm2300, scrp120aA, scrp120aC, scrp120aG);
		} catch (Exception e) {
			ExceptionProgram excp = new ExceptionProgram();
			excp.trataErroScrcerro(e, sessao, this.getClass().getSimpleName());
		}
	}

	private void main(Scrm2000 pscrm2000, Scrm2100 pscrm2100, Scrm220a pscrm220a, Scrm2300 pscrm2300, Scrp120aA pscrp120aA, Scrp120aC pscrp120aC, Scrp120aG pscrp120aG) throws Exception {
		if (pscrm2000 == null && pscrm2100 == null && pscrm220a == null && pscrm2300 == null && pscrp120aA == null && pscrp120aC == null && pscrp120aG == null) {
			primeiraVez = true;
			// scrm2000 = new Scrm2000 (primeiraVez);
			scrm2000 = preMapas();
			scrm2000.setNavegar("../scrp120a/executar");
			scrm2000.setMensagem(mensagemInicial);
			result.include("scrm2000", scrm2000);
			sessao.setAtributo("SCRP120A", this);
			scrm2000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());

			sessao.getScrg001().setWVltw(15);
			criminalView.wChv = "*";
			criminalView.wLoop += 1;
			scrm2300.setJocorrencia(1);
			return;
		} else {
			restaurarEstados(pscrm2000, pscrm2100, pscrm220a, pscrm2300, pscrp120aA, pscrp120aC, pscrp120aG);
		}

		switch (faseproc) {
		case "0": {
			scrm2000.receberTela(false, result);
			if (scrm2000.temMensagem) {
				result.include("scrm2000", scrm2000);
				sessao.setAtributo("SCRP120A", this);
				scrm2000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			// Par�grafo: fd33()
			criminalView.consultaRegEstadualGeral(scrm2000.getJregGeral());
			isn = criminalView.getId();// *ISN(0880);
			// && S-MAOESQ = criminalView.wMAO-ESQUERDA)
			if (criminalView.registrosProcessados() > 0) {
				if (criminalView.getStatusReg() == 5) {
					scrm2000.enviarMensagem("jregGeral", "Esta ficha esta� excluida - Nao pode ser alterada");
					result.include("scrm2000", scrm2000);
					sessao.setAtributo("SCRP120A", this);
					scrm2000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				String jdatanasc = String.valueOf(criminalView.getDataNasc());
				scrm2100.setDnas(UtilBean.subStr(jdatanasc, 6, 2));
				scrm2100.setMnas(UtilBean.subStr(jdatanasc, 4, 2));
				scrm2100.setAnas(UtilBean.subStr(jdatanasc, 0, 4));
				scrm220a.setJdataNasc(UtilBean.inverteDataDDMMYYYY(criminalView.getDataNasc()));
				scrm220a.setJdataregistro(UtilBean.inverteDataDDMMYYYY(criminalView.getDataReg()));
				scrm2100.setJpossuimandatopaberto(criminalView.getPossuiMandatoAberto());
				scrm2100.setJregGeral(criminalView.getRegEstadualGeral());
				scrm2100.setJnomecompleto(criminalView.getNomeCompleto());
				scrm2100.setJmae(criminalView.getNomeMae());
				scrm2100.setDedos(1, 1, criminalView.getPolegarDireito());
				scrm2100.setDedos(2, 1, criminalView.getIndicadorDireito());
				scrm2100.setDedos(3, 1, criminalView.getMedioDireito());
				scrm2100.setDedos(4, 1, criminalView.getAnularDireito());
				scrm2100.setDedos(5, 1, criminalView.getMinimoDireito());
				scrm2100.setDedos(1, 2, criminalView.getPolegarEsquerdo());
				scrm2100.setDedos(2, 2, criminalView.getIndicadorEsquerdo());
				scrm2100.setDedos(3, 2, criminalView.getMedioEsquerdo());
				scrm2100.setDedos(4, 2, criminalView.getAnularEsquerdo());
				scrm2100.setDedos(5, 2, criminalView.getMinimoEsquerdo());
				scrm220a.setJstatus(String.valueOf(criminalView.getStatusReg()));
				scrm220a.setJnomecompleto(criminalView.getNomeCompleto());
				scrm220a.setJpai(criminalView.getNomePai());
				scrm220a.setJmae(criminalView.getNomeMae());
				scrm220a.setJregGeral(criminalView.getRegEstadualGeral());
				scrm220a.setJidentidade(criminalView.getRegFederalCi());
				scrm220a.setJdelegacia(criminalView.getNomeDelegacia());
				scrm220a.setJdescmunicipio(criminalView.getMunicipioRegGeral());
				scrm220a.setJmunicipio(criminalView.getCodigoMunicipioRegGeral());
				scrm220a.setJufreggeral(criminalView.getUfRegEstadualGeral());
				scrm220a.setJnoautos(criminalView.getNumeroAutos());
				scrm220a.setJdataatuacao(UtilBean.inverteDataDDMMYYYY(criminalView.getDataAtuacao()));
				scrm220a.setJnomeanterior(criminalView.getNomeAnterior());
				scrm220a.setJalcunha(criminalView.getApelidoAlcunhas());
				scrm220a.setJsexo(criminalView.getSexo());
				scrm220a.setJnaturalidade(criminalView.getNaturalidade());
				scrm220a.setJcodmunnascimento(criminalView.getCodigoMunicipioNasc());
				scrm220a.setJufnascimento(criminalView.getUfNaturalidade());
				scrm220a.setJdocapresentado(criminalView.getDocumentoApresent());
				scrm220a.setJnumdocapresentado(criminalView.getNumDocumentoApresent());
				scrm220a.setJorgaoexpuf(criminalView.getOrgaoExpUfUfUf());
				scrm220a.setJprofissao(criminalView.getProfissao());
				scrm220a.setJinstrucao(criminalView.getGrauInstrucao());
				scrm220a.setJavrua(criminalView.getAvRua());
				scrm220a.setJnumero(criminalView.getNumero());
				scrm220a.setJbairro(criminalView.getBairro());
				scrm220a.setJmunendereco(criminalView.getMunicipio());
				scrm220a.setJufendereco(criminalView.getEstado());
				scrm220a.setJcep(criminalView.getCep());
				scrm220a.setJcomplemento(criminalView.getComplemento());
				scrm2300.setJaltura(String.valueOf(criminalView.getAltura()));
				scrm2300.setJestadocivil(String.valueOf(criminalView.getEstadoCivil()));
				scrm2300.setJcutis(String.valueOf(criminalView.getCodigoCutis()));
				scrm2300.setJcorcabelo(String.valueOf(criminalView.getCodigoCorCabelo()));
				scrm2300.setJtipocabelo(String.valueOf(criminalView.getCodigoTipoCabelo()));
				scrm2300.setJcorolhos(String.valueOf(criminalView.getCodigoCorOlhos()));
				scrm2300.setJsinais(criminalView.getMarcaPartCicatTatuag());
				scrm2300.setJcompleicao(String.valueOf(criminalView.getCompleicao()));
				scrm2300.setJnomevitima(criminalView.getNomeVitima());
				scrm2300.setJmotivo(criminalView.getMotivoPrisaoLei());
				scrm2300.setJobservacoes(criminalView.getObservacao());
				scrm220a.setJcpf(criminalView.getCpf());
				scrm2300.setJobservacoes(1, criminalView.getObservacao(1));
				scrm2300.setJobservacoes(2, criminalView.getObservacao(2));
				scrm2300.setJobservacoes(3, criminalView.getObservacao(3));
				scrm2300.setJobservacoes(4, criminalView.getObservacao(4));
				verStatus();

				faseproc = "1";
				result.include("scrm2100", scrm2100);
				sessao.setAtributo("SCRP120A", this);
				scrm2100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (criminalView.registrosProcessados() == 0) {
				// dao.rollback();
				scrm2000.enviarMensagem("jregGeral", "Ficha Criminal nao cadastrada");
				result.include("scrm2000", scrm2000);
				sessao.setAtributo("SCRP120A", this);
				scrm2000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
		}
			break;

		case "1": {
			scrm2100.receberTela(false, result);
			if (scrm2100.temMensagem) {
				result.include("scrm2100", scrm2100);
				sessao.setAtributo("SCRP120A", this);
				scrm2100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				Scrp120a scrp120a = new Scrp120a(result, sessao);
				scrp120a.executar(null, null, null, null, null, null, null);
				return;
			}

			criminalView.wData_nasc = scrm2100.getDnas() + scrm2100.getMnas() + scrm2100.getAnas();
			scrm220a.setJdataNasc(criminalView.wData_nasc);
			scrm220a.setJregGeral(scrm2100.getJregGeral());
			scrm220a.setJmae(scrm2100.getJmae());
			scrm220a.setJnomecompleto(scrm2100.getJnomecompleto());

			criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 0, 7, "A", scrm2100.getDedos(1, 1));
			criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 7, 7, "A", scrm2100.getDedos(2, 1));
			criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 14, 7, "A", scrm2100.getDedos(3, 1));
			criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 21, 7, "A", scrm2100.getDedos(4, 1));
			criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 28, 7, "A", scrm2100.getDedos(5, 1));

			criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 0, 7, "A", scrm2100.getDedos(1, 2));
			criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 7, 7, "A", scrm2100.getDedos(2, 2));
			criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 14, 7, "A", scrm2100.getDedos(3, 2));
			criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 21, 7, "A", scrm2100.getDedos(4, 2));
			criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 28, 7, "A", scrm2100.getDedos(5, 2));

			// Par�grafo: fd34()
			if (!scrm2100.getDedos('*', '*').trim().equals("") && criminalView.consultaMaoDireitaMaoEsquerda(
			// jMaoDireita,
			scrm2100.getDedos(1, 1), scrm2100.getDedos(2, 1), scrm2100.getDedos(3, 1), scrm2100.getDedos(4, 1), scrm2100.getDedos(5, 1),
			// jMaoEsquerda
			scrm2100.getDedos(1, 2), scrm2100.getDedos(2, 2), scrm2100.getDedos(3, 2), scrm2100.getDedos(4, 2), scrm2100.getDedos(5, 2))) {
				if (criminalView.getRegEstadualGeral() != scrm2100.getJregGeral()) {
					if (jCrime.trim().equals("")) {
						jCrime = "*";
						scrm2100.enviarMensagem(null, "Formula Datil. Ja�Cadastrada Anteriormente.Consulte-a ou- Tecle <ENTER> p/ Cont.");
						result.include("scrm2100", scrm2100);
						sessao.setAtributo("SCRP120A", this);
						scrm2100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
						return;
					}
				}
			}

			faseproc = "2";
			result.include("scrm220a", scrm220a);
			sessao.setAtributo("SCRP120A", this);
			scrm220a.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}

		case "2": {
			scrm220a.receberTela(false, result);
			if (scrm220a.temMensagem) {
				result.include("scrm220a", scrm220a);
				sessao.setAtributo("SCRP120A", this);
				scrm220a.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				result.include("scrm220a", scrm220a);
				sessao.setAtributo("SCRP120A", this);
				scrm220a.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			faseproc = "3";
			result.include("scrm2300", scrm2300);
			sessao.setAtributo("SCRP120A", this);
			scrm2300.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}

		case "3": {
			scrm2300.receberTela(false, result);
			if (scrm2300.temMensagem) {
				result.include("scrm2300", scrm2300);
				sessao.setAtributo("SCRP120A", this);
				scrm2300.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				Scrp120a scrp120a = new Scrp120a(result, sessao);
				scrp120a.executar(null, null, null, null, null, null, null);
				return;
			}

			criminalView.wData_atu = UtilBean.obtemDataCorrente();
			criminalView.wTempo = UtilBean.obtemHoraDia();
			// criminalView.wHora = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 0, 2));
			// criminalView.wMin = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 3, 2));
			// criminalView.wSeg = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 6, 2));
			// criminalView.wNse = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 9, 1));
			criminalView.wHora_atu = Integer.parseInt(UtilBean.obtemHoraDia());
			criminalView.wData_nasc0 = String.valueOf(scrm220a.getJdataNasc());
			criminalView.wData_nasc00 = Integer.parseInt(UtilBean.subStr(scrm220a.getJdataNasc(), 4, 4)) * 10000 + Integer.parseInt(UtilBean.subStr(scrm220a.getJdataNasc(), 2, 2)) * 100 + Integer.parseInt(UtilBean.subStr(scrm220a.getJdataNasc(), 0, 2));
			criminalView.wDataRegistro0 = Integer.parseInt(UtilBean.subStr(scrm220a.getJdataregistro(), 4, 4)) * 10000 + Integer.parseInt(UtilBean.subStr(scrm220a.getJdataregistro(), 2, 2)) * 100 + Integer.parseInt(UtilBean.subStr(scrm220a.getJdataregistro(), 0, 2));

			if (scrm2300.getJobservacoes(1).trim().equals("")) {
				if (criminalView.wChv.equals("*")) {
					criminalView.wChv = "";
					scrm2300.enviarMensagem(null, "Nenhuma ocorrencia foi informada.Se nao quiser- informar Tecle ENTER p/confirmar");
					result.include("scrm2300", scrm2300);
					sessao.setAtributo("SCRP120A", this);
					scrm2300.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
					return;
				}
			}
			// gravaOcorrencias(pscrm2300);
			if (scrm220a.getJmae().equals("*") || scrm220a.getJmae().trim().equals("")) {
				scrm220a.setJmae(jDozeAster);
			}
			if (scrm220a.getJpai().equals("*") || scrm220a.getJpai().trim().equals("")) {
				scrm220a.setJpai(jDozeAster);
			}
			for (jInd1 = 1; jInd1 <= 4; jInd1++) {
				if (scrm220a.getJalcunha(jInd1).trim().equals("") || scrm220a.getJalcunha(jInd1).equals("*")) {
					scrm220a.setJalcunha(jInd1, jDozeAster);
				}
			}
			if (scrm220a.getJnomeanterior().trim().equals("") || scrm220a.getJnomeanterior().equals("*")) {
				scrm220a.setJnomeanterior(jDozeAster);
			}
			if (scrm220a.getJnaturalidade().equals("*")) {
				scrm220a.setJnaturalidade(jDozeAster);
			}
			if (scrm220a.getJdocapresentado().equals("*")) {
				scrm220a.setJdocapresentado(jDozeAster);
			}
			if (scrm220a.getJavrua().equals("*")) {
				scrm220a.setJavrua(jDozeAster);
			}
			if (scrm220a.getJbairro().equals("*")) {
				scrm220a.setJbairro(jDozeAster);
			}
			if (scrm220a.getJcomplemento().trim().equals("") || scrm220a.getJcomplemento().equals("*")) {
				scrm220a.setJcomplemento(jDozeAster);
			}
			if (scrm2300.getJsinais().equals("*")) {
				scrm2300.setJsinais(jDozeAster);
			}
			if (scrm2300.getJnomevitima().equals("*")) {
				scrm2300.setJnomevitima(jDozeAster);
			}
			if (Integer.parseInt(scrm220a.getJdataatuacao()) < 1) {
				scrm220a.setJdataatuacao("0");
			}
			if (scrm220a.getJnoautos() < 1) {
				scrm220a.setJnoautos(0);
			}
			if (scrm220a.getJnumero() < 1L) {
				scrm220a.setJnumero(0);
			}
			if (scrm220a.getJnumdocapresentado() < 1) {
				scrm220a.setJnumdocapresentado(0);
			}
			if (scrm220a.getJcodmunnascimento() < 1) {
				scrm220a.setJcodmunnascimento(0);
			}
			if (scrm220a.getJufnascimento().trim().equals("")) {
				scrm220a.setJufnascimento("**");
			}
			if (scrm220a.getJcep() < 1) {
				scrm220a.setJcep(0);
			}
			if (scrm220a.getJmunendereco() < 1) {
				scrm220a.setJmunendereco(0);
			}
			if (scrm220a.getJufendereco().trim().equals("")) {
				scrm220a.setJufendereco("**");
			}
			if (scrm220a.getJprofissao().equals("*") || scrm220a.getJprofissao().trim().equals("")) {
				scrm220a.setJprofissao(jDozeAster);
			}
			if (scrm220a.getJorgaoexpuf().equals("*") || scrm220a.getJorgaoexpuf().trim().equals("")) {
				scrm220a.setJorgaoexpuf(jDozeAster);
			}

			criminalView.setObservacao(scrm2300.getJobservacoes());
			criminalView.setPossuiMandatoAberto(scrm2100.getJpossuimandatopaberto());
			criminalView.setRegEstadualGeral(scrm2000.getJregGeral());
			criminalView.setRegFederalCi(scrm220a.getJidentidade());
			criminalView.setStatusReg(Integer.parseInt(scrm220a.getJstatus()));
			criminalView.setTipoReg("AL");
			criminalView.setNomeCompleto(scrm220a.getJnomecompleto());
			criminalView.setNomePai(scrm220a.getJpai());
			criminalView.setNomeMae(scrm220a.getJmae());
			criminalView.setDataNasc(criminalView.wData_nasc00);
			criminalView.setPolegarDireito(scrm2100.getDedos(1, 1));
			criminalView.setIndicadorDireito(scrm2100.getDedos(2, 1));
			criminalView.setMedioDireito(scrm2100.getDedos(3, 1));
			criminalView.setAnularDireito(scrm2100.getDedos(4, 1));
			criminalView.setMinimoDireito(scrm2100.getDedos(5, 1));
			criminalView.setPolegarEsquerdo(scrm2100.getDedos(1, 2));
			criminalView.setIndicadorEsquerdo(scrm2100.getDedos(2, 2));
			criminalView.setMedioEsquerdo(scrm2100.getDedos(3, 2));
			criminalView.setAnularEsquerdo(scrm2100.getDedos(4, 2));
			criminalView.setMinimoEsquerdo(scrm2100.getDedos(5, 2));
			criminalView.setNomeDelegacia(scrm220a.getJdelegacia());
			criminalView.setMunicipioRegGeral(scrm220a.getJdescmunicipio());
			criminalView.setCodigoMunicipioRegGeral(scrm220a.getJmunicipio());
			criminalView.setUfRegEstadualGeral(scrm220a.getJufreggeral());
			criminalView.setDataReg(criminalView.wDataRegistro0);
			criminalView.setNumeroAutos(scrm220a.getJnoautos());
			criminalView.setDataAtuacao(Integer.parseInt(UtilBean.inverteDataToYYYYMMDD(scrm220a.getJdataatuacao())));
			criminalView.setNomeAnterior(scrm220a.getJnomeanterior());
			criminalView.setApelidoAlcunhas(scrm220a.getJalcunha());
			criminalView.setSexo(scrm220a.getJsexo());
			criminalView.setNaturalidade(scrm220a.getJnaturalidade());
			criminalView.setCodigoMunicipioNasc(scrm220a.getJcodmunnascimento());
			criminalView.setUfNaturalidade(scrm220a.getJufnascimento());
			criminalView.setDocumentoApresent(scrm220a.getJdocapresentado());
			criminalView.setNumDocumentoApresent(scrm220a.getJnumdocapresentado());
			criminalView.setOrgaoExpUfUfUf(scrm220a.getJorgaoexpuf());
			criminalView.setProfissao(scrm220a.getJprofissao());
			criminalView.setGrauInstrucao(scrm220a.getJinstrucao());
			criminalView.setAvRua(scrm220a.getJavrua());
			criminalView.setNumero(scrm220a.getJnumero());
			criminalView.setBairro(scrm220a.getJbairro());
			criminalView.setMunicipio((int) scrm220a.getJmunendereco());
			criminalView.setEstado(scrm220a.getJufendereco());
			criminalView.setCep(scrm220a.getJcep());
			criminalView.setComplemento(scrm220a.getJcomplemento());
			criminalView.setAltura(Integer.parseInt(scrm2300.getJaltura()));
			criminalView.setEstadoCivil(Integer.parseInt(scrm2300.getJestadocivil()));
			criminalView.setCodigoCutis(Integer.parseInt(scrm2300.getJcutis()));
			criminalView.setCodigoCorCabelo(Integer.parseInt(scrm2300.getJcorcabelo()));
			criminalView.setCodigoTipoCabelo(Integer.parseInt(scrm2300.getJtipocabelo()));
			criminalView.setCodigoCorOlhos(Integer.parseInt(scrm2300.getJcorolhos()));
			criminalView.setMarcaPartCicatTatuag(scrm2300.getJsinais());
			criminalView.setCompleicao(Integer.parseInt(scrm2300.getJcompleicao()));
			criminalView.setNomeVitima(scrm2300.getJnomevitima());
			criminalView.setMotivoPrisaoLei(scrm2300.getJmotivo());
			criminalView.setDataDocAtu(criminalView.wData_atu);
			criminalView.setHoraAtu(criminalView.wHora_atu);
			criminalView.setMatriculaFuncAtu(sessao.getScrg001().getWMatriculaw());
			criminalView.setCpf(scrm220a.getJcpf());

			funcoes.phonNome = scrm220a.getJnomecompleto();
			// Fonetizacao dos campos.
			// Phonet phonet = new Phonet ();
			funcoes.phonet(funcoes.phonArea);
			criminalView.setNomeCompletoPhon(funcoes.phonComb, 1, 168);
			if (scrm220a.getJmae() != jDozeAster) {
				funcoes.phonNome = scrm220a.getJmae();
				// Phonet phonet = new Phonet ();
				funcoes.phonet(funcoes.phonArea);
				criminalView.setNomeMaePhon(funcoes.phonComb, 1, 155);
			}
			if (scrm220a.getJpai() != jDozeAster) {
				funcoes.phonNome = scrm220a.getJpai();
				// Phonet phonet = new Phonet ();
				funcoes.phonet(funcoes.phonArea);
				criminalView.setNomePaiPhon(funcoes.phonComb, 1, 150);
			}
			for (jInd1 = 1; jInd1 <= 4; jInd1++) {
				if (scrm220a.getJalcunha(jInd1) != jDozeAster) {
					funcoes.phonNome = scrm220a.getJalcunha(jInd1);
					// Phonet phonet = new Phonet ();
					funcoes.phonet(funcoes.phonArea);
					jInd2 = jInd1 * 42;
					criminalView.setApelidoAlcunhasPhon(funcoes.phonComb, 1, 42);
				}
			}

			if (scrm2300.getJconf().trim().equals("")) {
				scrm2300.enviarMensagem("jconf", "Confirme �S� ou �N�");
				result.include("scrm2300", scrm2300);
				sessao.setAtributo("SCRP120A", this);
				scrm2300.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (!(scrm2300.getJconf().equals("S") || scrm2300.getJconf().equals("N"))) {
				scrm2300.enviarMensagem("jconf", "Confirmacao invalida");
				result.include("scrm2300", scrm2300);
				sessao.setAtributo("SCRP120A", this);
				scrm2300.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (scrm2300.getJconf().equals("N") || scrm2300.getJconf().trim().equals("")) {
				// dao.rollback();
				Scrp120a scrp120a = new Scrp120a(result, sessao);
				scrp120a.setMensagem("ATUALIZACAO NAO CONFIRMADA - TECLE <ENTER>");
				scrp120a.executar(null, null, null, null, null, null, null);
				return;
				// if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				// // dao.rollback();
				// scrp120a.setMensagem("ATUALIZACAO NAO CONFIRMADA - TECLE <ENTER>");
				// scrp120a.executar(null, null, null, null, null, null, null);
				// return;
				// }
			} else {
				if (criminalView.wLoop == 1) {
					faseproc = "4";
					result.include("scrp120aC", scrp120aC);
					sessao.setAtributo("SCRP120A", this);
					scrp120aC.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					return;
				} else {
					senhaView.consultaMatricula(sessao.getScrg001().getWMatriculaw());
					senhaView.setMatAtualizador(sessao.getScrg001().getWMatriculaw());
					senhaView.atualiza();
					senhaView.fecha();

					// criminalView.pesquisaPorId();
					criminalView.setId(isn);
					criminalView.atualiza();
					criminalView.fecha();

					scrm2000.setMensagem("REGISTRO ALTERADO COM SUCESSO - TECLE <ENTER>");
					result.include("scrm2000", scrm2000);
					sessao.setAtributo("SCRP120A", this);
					scrm2000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					break;
				}
			}
		}
		case "4": {
			scrp120aC.receberTela(false, result);
			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				// dao.rollback();
				Scrp120a scrp120a = new Scrp120a(result, sessao);
				scrp120a.setMensagem("ATUALIZACAO NAO CONFIRMADA - TECLE <ENTER>");
				scrp120a.executar(null, null, null, null, null, null, null);
				return;
			}
			if (scrp120aC.getJmat() == 0) {
				scrp120aC.enviarMensagem("jMat", "INFORME A MATRICULA");
				result.include("scrp120aC", scrp120aC);
				sessao.setAtributo("SCRP120A", this);
				scrp120aC.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (scrp120aC.getJmat() != sessao.getScrg001().getWMatriculaw()) {
				scrp120aC.enviarMensagem("jMat", "MATRICULA NAO CORRESPONDE A MATRICULA INICIAL");
				result.include("scrp120aC", scrp120aC);
				sessao.setAtributo("SCRP120A", this);
				scrp120aC.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (scrp120aC.getJsenha().trim().equals("")) {
				scrp120aC.enviarMensagem("jSenha", "INFORME SUA SENHA");
				result.include("scrp120aC", scrp120aC);
				sessao.setAtributo("SCRP120A", this);
				scrp120aC.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (!scrp120aC.getJsenha().trim().equals(sessao.getScrg001().getWSenhaw())) {
				scrp120aC.enviarMensagem("jSenha", "SENHA NAO CORRESPONDE A SENHA INICIAL");
				result.include("scrp120aC", scrp120aC);
				sessao.setAtributo("SCRP120A", this);
				scrp120aC.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			senhaView.consultaMatricula(sessao.getScrg001().getWMatriculaw());
			senhaView.setMatAtualizador(sessao.getScrg001().getWMatriculaw());
			senhaView.atualiza();
			senhaView.fecha();

			// criminalView.pesquisaPorId();
			criminalView.setId(isn);
			criminalView.atualiza();
			criminalView.fecha();

			faseproc = "0";
			scrm2000.setMensagem("REGISTRO ALTERADO COM SUCESSO - TECLE <ENTER>");
			result.include("scrm2000", scrm2000);
			sessao.setAtributo("SCRP120A", this);
			scrm2000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			break;
		}
		}

		// ATUALIZA DID-RG REGISTROS PARA ABN
		if (vwdidrg.consultaNumeroRg(scrm220a.getJregGeral())) {
			vwdidrg.setNumeroRg(scrm2000.getJregGeral());
			vwdidrg.setDataAtualizacao(UtilBean.obtemDataCorrente());
			vwdidrg.setHoraAtualizacao(Integer.parseInt(UtilBean.obtemHoraDia()));
			// abnFlag = "";
			vwdidrg.atualiza();
			vwdidrg.fecha();
		}
		// dao.commit();
		// dao.rollback();
		else {
			vwdidrg.setNumeroRg(scrm2000.getJregGeral());
			vwdidrg.setDataAtualizacao(UtilBean.obtemDataCorrente());
			vwdidrg.setHoraAtualizacao(Integer.parseInt((new SimpleDateFormat("HHmmssS").format(Calendar.getInstance().getTime()))));
			// abnFlag = "";
			vwdidrg.grava();
			vwdidrg.fecha();
			// dao.commit();
		}
		// ATUALIZA SIC-ESTATISTICAS NO CRIMINAL
		estla001.qde = 01;
		estla001.cpo = 02;
		sessao.getSisgsisp().setVlt(14);
		sessao.getSisgsisp().setVar(14);
		// ALTERA��O
		mod = tabm[14];
		estla001.esttip = 98;
		funcoes.estna001(estla001.cpo, estla001.esttip, estla001.qde, var, sessao.getScrg001().getWMatriculaw());
	}// FIM

	private void gravaOcorrencias(Scrm2300 pscrm2300) {
		int ind = 0;
		criminalView.wI = 5;
		if (!scrm2300.getJobservacoes(1).trim().equals("")) {
			if (!((UtilBean.funcao.equals(UtilBean.ctt_retorna) || UtilBean.funcao.equals(UtilBean.ctt_processa)))) {
				scrm2300.enviarMensagem(null, "Tecla invalida");
				return;
			}
			criminalView.wObservacoez[1] = scrm2300.getJobservacoes(1);
			criminalView.wObservacoez[2] = scrm2300.getJobservacoes(2);
			criminalView.wObservacoez[3] = scrm2300.getJobservacoes(3);
			criminalView.wObservacoez[4] = scrm2300.getJobservacoes(4);
		}

		for (ind = 2; ind <= 40; ind++) {
			scrm2300.setJocorrencia(ind);
			if (scrm2300.getJocorrencia() == 2) {
				criminalView.wJ = scrm2300.getJocorrencia() + 4;
				criminalView.wL = scrm2300.getJocorrencia() + 5;
				criminalView.wM = scrm2300.getJocorrencia() + 6;
			} else {
				criminalView.wI = criminalView.wM + 1;
				criminalView.wJ = criminalView.wM + 2;
				criminalView.wL = criminalView.wM + 3;
				criminalView.wM = criminalView.wM + 4;
			}
			scrm2300.setJobservacoes(1, criminalView.wObservacoez[criminalView.wI]);
			scrm2300.setJobservacoes(2, criminalView.wObservacoez[criminalView.wJ]);
			scrm2300.setJobservacoes(3, criminalView.wObservacoez[criminalView.wL]);
			scrm2300.setJobservacoes(4, criminalView.wObservacoez[criminalView.wM]);

			if (!scrm2300.getEnviada()) {
				result.include("scrm2300", scrm2300);
				sessao.setAtributo("SCRP120A", this);
				scrm2300.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (pscrm2300 != null) {
				scrm2300.receberTela(false, result);
			}
			//
			if (!((UtilBean.funcao.equals(UtilBean.ctt_retorna) || UtilBean.funcao.equals(UtilBean.ctt_processa)))) {
				scrm2300.enviarMensagem(null, "TECLA INVALIDA");
				return;
			}
			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				Scrp120a scrp120a = new Scrp120a(result, sessao);
				scrp120a.executar(null, null, null, null, null, null, null);
				return;
			}
			// IF scrm2300.getJobservacoes(1) = ' '
			// ESCAPE BOTTOM
			// END-IF
			criminalView.wObservacoez[criminalView.wI] = scrm2300.getJobservacoes(1);
			criminalView.wObservacoez[criminalView.wJ] = scrm2300.getJobservacoes(2);
			criminalView.wObservacoez[criminalView.wL] = scrm2300.getJobservacoes(3);
			criminalView.wObservacoez[criminalView.wM] = scrm2300.getJobservacoes(4);
			// RESET scrm2300.getJobservacoes(*)
			for (criminalView.wX = 4; criminalView.wX >= 2; criminalView.wX += -1) {
				if (!scrm2300.getJobservacoes(criminalView.wX).trim().equals("")) {
					criminalView.wW = criminalView.wX - 1;
					for (criminalView.wY = criminalView.wW; criminalView.wY >= 1; criminalView.wY += -1) {
						if (scrm2300.getJobservacoes(criminalView.wY).trim().equals("")) {
							scrm2300.enviarMensagem(null, "");
							return;
						}
					}
				}
			}
			if (scrm2300.getJobservacoes(1).trim().equals("")) {
				break;
			}
		}
	}

	// END-IF
	private void verStatus() {
		switch (criminalView.getStatusReg()) {
		case 0: {
			scrm220a.setJdescreg("Registro Normal");
			break;
		}
		case 1: {
			scrm220a.setJdescreg("Registro Cancelado");
			break;
		}
		case 2: {
			scrm220a.setJdescreg("Registro com Mandato de Prisao preventiva");
			break;
		}
		case 3: {
			scrm220a.setJdescreg("Condenado");
			break;
		}
		default: {
			scrm220a.setJdescreg("");
			break;
		}
		}
	}

	private void restaurarEstados(Scrm2000 pscrm2000, Scrm2100 pscrm2100, Scrm220a pscrm220a, Scrm2300 pscrm2300, Scrp120aA pscrp120aA, Scrp120aC pscrp120aC, Scrp120aG pscrp120aG) {
		this.scrp120aAnterior = (Scrp120a) sessao.getAtributo("SCRP120A");
		if (pscrm2000 != null) {
			scrm2000 = pscrm2000;
			scrm2000.setJfuncaoj(sessao.getScrg001().getWFuncaow());
			scrm2000.setJversaoj(sessao.getScrg001().getWVersaow());
			scrm2000.setJempresaj(sessao.getScrg001().getWEmpresaw());
			scrm2000.setJprogramaj(sessao.getScrg001().getWProgramaw());
		} else {
			scrm2000 = this.scrp120aAnterior.scrm2000;
		}
		scrm2000.setSessao(sessao);
		if (pscrm2100 != null) {
			scrm2100 = pscrm2100;
			scrm2100.setJfuncaoj(sessao.getScrg001().getWFuncaow());
			scrm2100.setJversaoj(sessao.getScrg001().getWVersaow());
			scrm2100.setJempresaj(sessao.getScrg001().getWEmpresaw());
			scrm2100.setJprogramaj(sessao.getScrg001().getWProgramaw());
		} else {
			scrm2100 = this.scrp120aAnterior.scrm2100;
		}
		scrm2000.setSessao(sessao);
		if (pscrm220a != null) {
			scrm220a = pscrm220a;
			scrm220a.setJfuncaoj(sessao.getScrg001().getWFuncaow());
			scrm220a.setJversaoj(sessao.getScrg001().getWVersaow());
			scrm220a.setJempresaj(sessao.getScrg001().getWEmpresaw());
			scrm220a.setJprogramaj(sessao.getScrg001().getWProgramaw());
		} else {
			scrm220a = this.scrp120aAnterior.scrm220a;
		}
		scrm220a.setSessao(sessao);
		if (pscrm2300 != null) {
			scrm2300 = pscrm2300;
			scrm2300.setJfuncaoj(sessao.getScrg001().getWFuncaow());
			scrm2300.setJversaoj(sessao.getScrg001().getWVersaow());
			scrm2300.setJempresaj(sessao.getScrg001().getWEmpresaw());
			scrm2300.setJprogramaj(sessao.getScrg001().getWProgramaw());
		} else {
			scrm2300 = this.scrp120aAnterior.scrm2300;
		}
		scrm2300.setSessao(sessao);
		if (pscrp120aA != null) {
			scrp120aA = pscrp120aA;
			scrp120aA.setjversaoj(sessao.getScrg001().getWVersaow());
			scrp120aA.setjempresaj(sessao.getScrg001().getWEmpresaw());
			scrp120aA.setjprogramaj(sessao.getScrg001().getWProgramaw());
		} else {
			scrp120aA = this.scrp120aAnterior.scrp120aA;
		}
		scrp120aA.setSessao(sessao);
		if (pscrp120aC != null) {
			scrp120aC = pscrp120aC;
			scrp120aC.setjversaoj(sessao.getScrg001().getWVersaow());
			scrp120aC.setjempresaj(sessao.getScrg001().getWEmpresaw());
			scrp120aC.setjprogramaj(sessao.getScrg001().getWProgramaw());
		} else {
			scrp120aC = this.scrp120aAnterior.scrp120aC;
		}
		scrp120aC.setSessao(sessao);
		if (pscrp120aG != null) {
			scrp120aG = pscrp120aG;
			scrp120aG.setjversaoj(sessao.getScrg001().getWVersaow());
			scrp120aG.setjempresaj(sessao.getScrg001().getWEmpresaw());
			scrp120aG.setjprogramaj(sessao.getScrg001().getWProgramaw());
		} else {
			scrp120aG = this.scrp120aAnterior.scrp120aG;
		}
		scrp120aG.setSessao(sessao);
		this.faseproc = this.scrp120aAnterior.faseproc;
		this.isn = this.scrp120aAnterior.isn;
		this.criminalView = this.scrp120aAnterior.criminalView;
	}

	protected void setMensagem(String mensagem) {
		mensagemInicial = mensagem;
	}
}
